﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>ComObjGet - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The ComObjGet function returns a reference to an object provided by a COM component." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>ComObjGet</h1>
<p>返回对 COM 组件提供的对象的引用.</p>
<pre class="Syntax">ComObj := <span class="func">ComObjGet</span>(Name)</pre>

<h2 id="Parameters">参数</h2>
<dl>

  <dt>Name</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>要检索的对象的显示名称. 有关详情, 请参阅 <a href="http://msdn.microsoft.com/en-us/library/ms691253.aspx">MkParseDisplayName (MSDN)</a>.</p>
  </dd>

</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../ComObject.htm">ComObject</a></p>
<p>此函数返回新的 COM 包装对象, 其<a href="ComObjType.htm#vt">变体类型</a>为 VT_DISPATCH (9).</p>

<h2 id="Error_Handling">错误处理</h2>
<p>失败时抛出异常.</p>

<h2 id="Related">相关</h2>
<a href="ComObject.htm">ComObject</a>, <a href="ComObjActive.htm">ComObjActive</a>, <a href="ComObjConnect.htm">ComObjConnect</a>, <a href="ComObjQuery.htm">ComObjQuery</a>, <a href="http://msdn.microsoft.com/en-us/library/ms678805.aspx">CoGetObject (MSDN)</a>

<h2 id="Examples">示例</h2>
<div class="ex" id="exwmi">
<p><a class="ex_number" href="#exwmi"></a> 按下 <kbd>Shift</kbd>+<kbd>Esc</kbd> 来显示活动窗口进程的命令行.</p>
<pre>+Esc::
{
    pid := WinGetPID("A")
    <em>; 获取 WMI 服务对象.</em>
    wmi := ComObjGet("winmgmts:")
    <em>; 执行查询以获取匹配进程.</em>
    queryEnum := wmi.ExecQuery(""
        . "Select * from Win32_Process where ProcessId=" . pid)
        ._NewEnum()
    <em>; 获取首个匹配进程.</em>
    if queryEnum(&amp;proc)
        MsgBox(proc.CommandLine, "Command line", 0)
    else
        MsgBox("Process not found!")
}
<em>; Win32_Process: <a href="http://msdn.microsoft.com/en-us/library/aa394372.aspx">http://msdn.microsoft.com/en-us/library/aa394372.aspx</a></em>
</pre>
</div>

</body>
</html>